package web.dao.Impl;

import web.bean.Tousu;
import web.bean.Zichan;
import web.dao.TouSuDao;
import web.utils.DBUtil;

import java.util.List;

public class TouSuDaoImpl implements TouSuDao {
    @Override
    public List<Tousu> findInfo(Integer params1, Integer params2, String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Tousu.class, "addtime>=? and addtime<=? and suoshuxiaoqu like ?  limit ?,?", startTime, endTime, "%" + name + "%", params1, params2);
    }

    @Override
    public int count(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Tousu.class, "addtime>=? and addtime<=? and suoshuxiaoqu like ? ", startTime, endTime, "%" + name + "%").size();
    }

    @Override
    public int add(Tousu tousu) {
        return DBUtil.insert(tousu);
    }

    @Override
    public int del(Integer[] delIds) {
        String where= "id in (";
        for (int i = 0; i < delIds.length; i++) {
            where+="?";
            if (i!=delIds.length-1){
                where+=",";
            }else {
                where+=")";
            }
        }
        return DBUtil.delete(Tousu.class,where,delIds);
    }

    @Override
    public int editInfo(Tousu tousu) {
        return DBUtil.updateSelective(tousu,"id=?",tousu.getId());
    }

    @Override
    public Tousu findTouSu(Integer id) {
        return DBUtil.findOneByWhere(Tousu.class,"id=?",id);
    }
}
